<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>认款 管理</title>
    <style type="text/css">
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">客户名称</div>
                    <div class="field">
                        <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="${cstNm}">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">合同号</div>
                    <div class="field">
                        <input name="lsCntNo" id="lsCntNo" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="formBtns notRight">
                    <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                    <%--<span id="resetFundBtn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_19"></i>重置未认款</span>--%>
                    <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                </div>
            </div>
        </form>
    </div>

    <div id="ligergrid1" class="sq-grid"></div>
</div>

<form id="capFundConfirm_form" style="display: none;">
    <div class="fieldset1 clearFix">
        <div class="fieldBox">
            <span>是否确定此人为来款人？</span>
        </div>
        <div class="fieldBox">
            <div class="label">认款备注</div>
            <div class="field">
                <textarea name="docketRem" id="docketRem" class="ui-textarea l-textarea"
                          rows="4" cols="60" style="width: 260px;" validate="{required:false,maxlength:200}"></textarea>
            </div>
        </div>
    </div>
</form>

<script type="text/javascript">
    var grid = null, fundId=null,form=null,vfFlag=null;
    $(function () {
        fundId="${fundId}";//资金ID
        vfFlag="${vfFlag}";//是否需要自动核销
        form=$("#searchBar").ligerForm();

        grid = $("#ligergrid1").ligerGrid({
            url: '<%=path%>/capital/capFund/initCstList.do',
            method : 'get',
            parms:getSearchParams(),
            columns: [
                {display: '客户名称', name: 'cstNm', minWidth: 100, align: 'center',isEllipsis: false,
                    render:function (rowdata,rowindex,value) {
                        if (value) {
                            return '<span class="gridTip" title="' + value + '">' + value + '</span>'
                        }
                    }
                },
                {display: '证件/机构代码', name: 'certNo', width: 100, align: 'left',isEllipsis: false},
                {display: '合同号', name: 'contNo', width: 280, align: 'left',isEllipsis: false},
                {display: '操作', width: 50, align: 'center',
                    render:function(rowdata,index,value){
                        return '<a onclick="confirmFund('+rowdata.cstId+',\''+rowdata.cstNm+'\');"></i>确认</a>';
                    }
                },
            ],
            pageSize: 50,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            fixedCellHeight: false,
            rownumbers: true,
            allowUnSelectRow: true
        });
        grid.setHeight(100);

        $("#pageloading").hide();

        /* 查询 */
        $("#searchBtn").click(function (event) {
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
        });

        //查询参数
        function getSearchParams(){
            var data = form.getData();
            return data;
        }

        $("#resetFundBtn").click(function(){
            $.ligerDialog.confirm("是否确定重置为未认款？", function (flag) {
                if (flag == false)return;
                var wait_dialog;
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: {id: fundId,cstId:"",cstNm:""},
                    url: '<%=path%>/capital/capFund/confirmFund.do',
                    beforeSend: function () {
                        wait_dialog = $.ligerDialog.SQalert({
                            content: LogUtils.LOG_CMM_DATA_LOADING,
                            SQ_type: "waitting"
                        });
                    },
                    success: function (msg) {
                        wait_dialog.close();
                        if (msg.success == 1) {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                            parent.$("#searchBtn").click();
                        } else {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                        }
                    }
                });
            });
        });
    });

    //确认款项
    function confirmFund(cstId,cstNm) {
        if(vfFlag==1) {//认款自动核销
            var onOk = function (item, Dialog) {
                var remark=$("#docketRem").val();
                modifyFund(cstId, cstNm,remark);
            };
            var onCancel = function (item, Dialog) {
                Dialog.hide();
            };
            $.ligerDialog.SQopen({
                width: 400,
                title : '认款确认',
                target : $('#capFundConfirm_form'),
                buttons: [
                    {
                        text: "确认", onclick: onOk, type: 'ok', cls: 'l-dialog-btn-ok'
                    },
                    {
                        text: "取消", onclick: onCancel, type: 'cancel', cls: 'l-dialog-btn-no'
                    }
                ]
            });
        }else{
            $.ligerDialog.confirm("是否确定此人为来款人？", function (flag) {
                if (flag == false)return;
                modifyFund(cstId, cstNm,"");
            });
        }
    }

    //修改资金认款人
    function modifyFund(cstId,cstNm,remark){
        var wait_dialog;
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: {id: fundId,cstId:cstId,cstNm:cstNm,vfFlag:vfFlag,docketRem:remark},
            url: '<%=path%>/capital/capFund/confirmFund.do',
            beforeSend: function () {
                wait_dialog = $.ligerDialog.SQalert({
                    content: LogUtils.LOG_CMM_DATA_LOADING,
                    SQ_type: "waitting"
                });
            },
            success: function (msg) {
                wait_dialog.close();
                if (msg.success == 1) {
                    top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                    parent.$("#searchBtn").click();
                    frameElement.dialog.close();
                } else {
                    top.$.ligerDialog.SQalert({content: msg.info, SQ_showButtons : true,SQ_type: "error"});
                }
            }
        });
    }

</script>

</body>
</html>
